import { defineStore } from "pinia";

// 给仓库起名字
export const useLoginStore = defineStore("login", {
    state: () => {
        return {
            token: "",
            permission: "",
            username: ""
        };
    },
    actions: {
        // 设置登录信息
        setLoginInfo(token, permission, username) {
            this.token = token;
            this.permission = permission;
            this.username = username;
        },
        // 清除登录信息
        clearLoginInfo() {
            this.token = "";
            this.permission = "";
            this.username = "";
        }
    },
    // 持久化配置
    persist: {
        enabled: true,
        key: 'login-store',
        storage: localStorage,
        paths: ['token', 'permission', 'username']
    }
})